const daoCommon = require('../util/daoCommon');
const commonUtils = require('../util/commonUtils');

const dao = {
    handleLogin: (data) => {
        let sql;
        if (data) {
            sql = "select count(*) as count from admin where username=$username and password=$password and is_delete='0'";
        }
        return daoCommon.loginCommon(sql, data);
    },
    handleAddAccount: (data) => {
        let sql;
        let date = new Date();
        data.createTime = date.toLocaleString();
        if (data) {
            sql = `insert into admin values($username,$password,null,$createTime,null,null,null,'0')`;
        }
        return daoCommon.queryCommon(sql, data);
    },
    searchAdminByName: (data) => {
        let sql;
        sql = `select * from admin where username=$username`;
        return daoCommon.selectCommon(sql, data);
    },
    handleEditAccount: (data) => {
        let sql;
        let date = new Date();
        data.updateTime = date.toLocaleString();
        sql = `update admin set password=$password,updated_time=$updateTime where username=$username`;
        return daoCommon.queryCommon(sql, data);
    },
    handleDeleteAccount: (data) => {
        let sql;
        sql = `update admin set is_delete='1' where username=$username`;
        return daoCommon.queryCommon(sql, data);
    },
    handleGetAccountList: () => {
        let sql;
        sql = `select username,created_time from admin where is_delete='0'`;
        return daoCommon.selectCommon(sql);
    },
    handleAddToken: (data) => {
        let sql;
        sql = `update admin set token=$token where username=$username`;
        return daoCommon.queryCommon(sql, data);
    }
};
module.exports = dao;